<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--引入vue和axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!-- 全局的基础配置文件 -->
    <script src="js/plugins/common.js"></script>
</head>
<body>
<div id="myApp">
</div>
</body>
<script type="text/javascript">
    new Vue({
        el:"#myApp",
        data:{},
        mounted(){
            //http://bugtracker.itsource.cn/callback.html?code=031QtAll2kBeA64RzJol2gpcaW3QtAlk&state=1
            let url = location.href;
            let code = parseUrlParams2Obj(url).code;
            //获取请求发送参数并发送微信登录请求
            this.$http.get("/login/wechat/"+code).then(res => {
                if(res.data.success){//绑定成功 - 免密登录
                    //提示
                    alert("登录成功!!!");
                    //保存token和logininfo对象到localStorage
                    var token = res.data.resultObj.token;
                    var logininfo = res.data.resultObj.logininfo;
                    localStorage.setItem("token",token);
                    //localStorage保存的数据是字符串，所以要将json对象转成json格式的字符串
                    localStorage.setItem("logininfo",JSON.stringify(logininfo));
                    location.href = "/index.html";
                }else{//没有绑定
                    //跳转到绑定页面
                    var access_token = res.data.resultObj.access_token;
                    var openid = res.data.resultObj.openid;
                    location.href = "/binder.html?accessToken="+access_token+"&openId="+openid;
                }
            }).catch(res=>{
                console.log(res);
            });
        }
    });
</script>
</html>